package com.wejoy.video.middle.station.admin.controller.system;

import com.wejoy.video.middle.station.admin.util.CurrentUserUtils;
import com.wejoy.video.middle.station.admin.controller.BaseController;
import com.wejoy.video.middle.station.data.annotation.RoleCheck;
import com.wejoy.video.middle.station.data.domain.system.SysUser;
import com.wejoy.video.middle.station.data.service.system.ISysRoleResourceService;
import com.wejoy.video.middle.station.data.vo.RespJSON;
import com.wejoy.video.middle.station.data.vo.system.SysRoleResourceVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 系统-角色权限关联表
 *
 * @author admin
 * @date 2021年10月19日 15:06:41
 */
@RestController
@RequestMapping("/system/sysRoleResource")
public class SysRoleResourceController extends BaseController {

    @Autowired
    private ISysRoleResourceService sysRoleResourceService;

    /**
     * 添加角色按此单
     * @param roleResourceVO
     * @param loginSysUser
     * @return
     */
    @PostMapping("/addResource")
    @RoleCheck(name = "sys_role_addResource")
    public RespJSON addResource(@RequestBody SysRoleResourceVO roleResourceVO, @SessionAttribute(CurrentUserUtils.SYSTEM_USER) SysUser loginSysUser) {
        sysRoleResourceService.addResource(roleResourceVO, loginSysUser.getUserName());
        return RespJSON.success();
    }

    /**
     * 根据角色ID查询所拥有菜单权限
     *
     * @param roleResourceVO
     * @return RespJSON
     */
    @PostMapping("/getResourcesIdListByRoleId")
    public RespJSON getResourcesIdListByRoleId(@RequestBody SysRoleResourceVO roleResourceVO) {
        return RespJSON.success(sysRoleResourceService.getResourcesIdListByRoleId(roleResourceVO.getRoleId()));
    }

}
